package com.itheima.service.impl;

import com.itheima.mapper.OrderSettingMapper;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingMapper orderSettingMapper;


    // 根据月份查询预约设置数据
    @Override
    public List<OrderSetting> getOrderSettingByMonth(String month) {
        /*//LocalDate.parse(month) 默认期望的日期格式是 yyyy-MM-dd，所以
        // 确保月份部分有前导零
        if (month.length() == 6) {// 如果月份只有5位，则补0
            month = month.substring(0, 5) + "0" + month.substring(5);// 在5号位置插入0
        }
        month = month + "-01"; // 拼接上1号
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // 指定日期格式
        LocalDate date = LocalDate.parse(month, formatter); // 使用自定义格式解析*/
        return orderSettingMapper.getOrderSettingByMonth(month);
    }

    // 根据预约日期修改预约
    @Override
    public void editNumberByOrderDate(OrderSetting orderSetting) {
        orderSettingMapper.editNumberByOrderDate(orderSetting);

    }

    //文件上传
    @Override
    public void upload(List<OrderSetting> orderSettings) {

        for (OrderSetting orderSetting : orderSettings) {
            orderSettingMapper.editNumberByOrderDate(orderSetting);
        }

    }
}
